/**
 * 
 */
package org.pump.client.type;

import org.apache.mina.core.buffer.IoBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author liudong03
 *
 */
public class QueryStatus {
	private static final Logger mylog = LoggerFactory
			.getLogger(QueryStatus.class);
	byte[] flags = new byte[4];
	byte[] sql_modes = new byte[8];
	Varstr catalog;
	int increment_offset;
	int increment_step;
	int charset_set_client;
	int collation_connection;
	int collation_server;
	Varstr time_zone;
	int lc_times_names_number;
	int charset_database_number;
	byte[] table_map = new byte[8];
	int len;
	byte [] content;
	
	public static QueryStatus readBuffer(IoBuffer in,int len)
	{
		if(in.remaining() < len)
		{
			return null;
		}
		QueryStatus mystatus = new QueryStatus();
		mystatus.content = new byte[len];
		in.get(mystatus.content);
		/*
		int sz = 0;
		for(;sz < len;)
		{
			short typecode = in.getUnsigned();
			switch(typecode)
			{
			case 0:
				in.get(mystatus.flags);
				sz += 4;
				break;
			case 1:
				in.get(mystatus.sql_modes);
				sz += 8;
				break;
			case 6:
				mystatus.catalog = Varstr.readBuffer(in,"US-ASCII");
				sz += mystatus.catalog.getSize();
				if(mystatus.catalog == null)
				{
					mylog.info("read status catalog fail");
					return null;
				}
				break;
			case 3:
				mystatus.increment_offset = in.getUnsignedShort();
				mystatus.increment_step = in.getUnsignedShort();
				sz += 4;
				break;
			case 4:
				mystatus.charset_set_client = in.getUnsignedShort();
				mystatus.collation_connection = in.getUnsignedShort();
				mystatus.collation_server = in.getUnsignedShort();
				sz += 6;
				break;
			case 5:
				mystatus.time_zone = Varstr.readBuffer(in,"US-ASCII");
				if(mystatus.time_zone == null)
				{
					mylog.info("read time_zone fail");
					return null;
				}
				sz += mystatus.time_zone.getSize();
				break;
			case 7:
				mystatus.lc_times_names_number = in.getUnsignedShort();
				sz += 2;
				break;
			case 8:
				mystatus.charset_database_number = in.getUnsignedShort();
				sz += 2;
				break;
			case 9:
				in.get(mystatus.table_map);
				sz += 8;
				break;
			default:
				mylog.error("unsupported query status");
			}//switch
		}//for
		
		
		mylog.info("read query status info succ" + sz);*/
		return mystatus;
	}
	/**
	 * 
	 */
	public QueryStatus() {
		// TODO Auto-generated constructor stub
	}

}
